package com.itheima.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.mapper.PmsProductLadderMapper;
import com.itheima.pojo.PmsProductLadder;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class PmsProductLadderImpl implements PmsProductLadderApi {

    @Autowired
    private PmsProductLadderMapper mapper;

    /**
     *商品添加
     */
    @Override
    public void save(List<PmsProductLadder> productLadderList,Long productId) {

        for (PmsProductLadder pmsProductLadder : productLadderList) {
                  pmsProductLadder.setProductId(productId);
                  mapper.insert(pmsProductLadder);
        }
    }

    /**
     *根据商品id获取商品编辑信息
     */
    @Override
    public List<PmsProductLadder> updateInfo(Integer productId) {
        LambdaQueryWrapper<PmsProductLadder> lqw = new LambdaQueryWrapper<>();
        lqw.eq(PmsProductLadder::getProductId,productId);
        List<PmsProductLadder> pmsProductLadders = mapper.selectList(lqw);
        return pmsProductLadders;
    }

    /**
     *更新商品
     */
    @Override
    public void updateProduct(List<PmsProductLadder> productLadderList, Long productId) {
        for (PmsProductLadder pmsProductLadder : productLadderList) {
            pmsProductLadder.setProductId(productId);
            mapper.updateById(pmsProductLadder);
        }
    }

}
